package org.soma.sso.server;

import org.soma.sso.server.filter.SsoServerFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {"org.soma"})
@ImportResource(value = {"classpath:/config/applicationContext-*.xml"})
public class StarterServer {
	public static void main(String[] args) throws Exception {
		SpringApplication.run(StarterServer.class, args);
	}

	@Value("${SSO_SERVER_URL}")
	private String ssoServerUrl;

	@Value("${SSO_SERVER_VERIFY_URL}")
	private String ssoServerVerifyUrl;


	@Bean
	public FilterRegistrationBean testFilterRegistration() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(new SsoServerFilter());
		registration.addUrlPatterns("/sso/*");
		//registration.addInitParameter("SSO_SERVER_URL", ssoServerUrl);
		//registration.addInitParameter("SSO_SERVER_VERIFY_URL", ssoServerVerifyUrl);
		registration.setName("ssoServerFilter");
		registration.setOrder(1);
		return registration;
	}
}
